package com.ss.android.common.ui.view;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.text.Layout.Alignment;
import android.text.Layout;
import android.text.StaticLayout;
import android.text.TextPaint;

public final class TextDrawable extends Drawable {
    public Resources a;
    public CharSequence b;
    private TextPaint c;
    private StaticLayout d;
    private Layout.Alignment e;
    private ColorStateList f;
    private Rect g;
    private static final int[] h;
    private static final int[] i;

    static {
        h = new int[]{16842804};
        i = new int[]{16842901, 16842902, 16842903, 16842904};
    }

    public TextDrawable(Context arg14) {
        int v2_1;
        ColorStateList v0_1;
        Typeface v4 = null;
        int v0 = -1;
        boolean v6 = false;

        this.e = Layout.Alignment.ALIGN_NORMAL;
        this.b = "";
        this.a = arg14.getResources();
        this.g = new Rect();
        this.c = new TextPaint(1);
        this.c.density = this.a.getDisplayMetrics().density;
        this.c.setDither(true);
        int v3 = 15;
        TypedArray v10 = arg14.getTheme().obtainStyledAttributes(h);
        int v1 = v10.getResourceId(0, v0);
        v10.recycle();
        TypedArray v9 = v1 != v0 ? arg14.obtainStyledAttributes(v1, i) : ((TypedArray)null);
        if(v9 != null) {
            v1 = v0;
            ColorStateList v2 = ((ColorStateList)null);
            int v5;
            for(v5 = 0; v5 < v9.getIndexCount(); ++v5) {
                int v11 = v9.getIndex(v5);
                switch(v11) {
                    case 0: {
                        v3 = v10.getDimensionPixelSize(v11, v3);
                        break;
                    }
                    case 1: {
                        v0 = v10.getInt(v11, v0);
                        break;
                    }
                    case 2: {
                        v1 = v10.getInt(v11, v1);
                        break;
                    }
                    case 3: {
                        v2 = v10.getColorStateList(v11);
                        break;
                    }
                }
            }

            v9.recycle();
            int v12 = v0;
            v0_1 = v2;
            v2_1 = v1;
            v1 = v12;
        }
        else {
            v1 = v0;
            v2_1 = v0;
            v0_1 = ((ColorStateList)null);
        }

        if(v0_1 == null) {
            v0_1 = ColorStateList.valueOf(-16777216);
        }

        this.a(v0_1);
        this.a(((float)v3));
        switch(v1) {
            case 1: {
                v4 = Typeface.SANS_SERIF;
                break;
            }
            case 2: {
                v4 = Typeface.SERIF;
                break;
            }
            case 3: {
                v4 = Typeface.MONOSPACE;
                break;
            }
        }

        if(v2_1 > 0) {
            Typeface v0_2 = v4 == null ? Typeface.defaultFromStyle(v2_1) : Typeface.create(v4, v2_1);
            this.a(v0_2);
            v0 = v0_2 != null ? v0_2.getStyle() : 0;
            v0 = (v0 ^ -1) & v2_1;
            TextPaint v1_1 = this.c;
            if((v0 & 1) != 0) {
                v6 = true;
            }

            v1_1.setFakeBoldText(v6);
            v1_1 = this.c;
            float v0_3 = (v0 & 2) != 0 ? -0.25f : 0f;
            v1_1.setTextSkewX(v0_3);
        }
        else {
            this.c.setFakeBoldText(false);
            this.c.setTextSkewX(0f);
            this.a(v4);
        }
    }

    public final void a(float arg2) {
        if(arg2 != this.c.getTextSize()) {
            this.c.setTextSize(arg2);
            this.a();
        }
    }

    public final void a(Typeface arg2) {
        if(this.c.getTypeface() != arg2) {
            this.c.setTypeface(arg2);
            this.a();
        }
    }

    public final void a() {
        this.d = new StaticLayout(this.b, this.c, ((int)Math.ceil(((double)Layout.getDesiredWidth(this.b, this.c)))), this.e, 1f, 0f, true);
        this.g.set(0, 0, this.d.getWidth(), this.d.getHeight());
        this.invalidateSelf();
    }

    public final void a(int arg2) {
        this.a(ColorStateList.valueOf(arg2));
    }

    private void a(ColorStateList arg2) {
        this.f = arg2;
        this.a(this.getState());
    }

    private boolean a(int[] arg3) {
        boolean v0_1;
        int v0 = this.f.getColorForState(arg3, -1);
        if(this.c.getColor() != v0) {
            this.c.setColor(v0);
            v0_1 = true;
        }
        else {
            v0_1 = false;
        }

        return v0_1;
    }

    public final void draw(Canvas arg4) {
        Rect v0 = this.getBounds();
        int v1 = arg4.save();
        arg4.translate(((float)v0.left), ((float)v0.top));
        this.d.draw(arg4);
        arg4.restoreToCount(v1);
    }

    public final int getIntrinsicHeight() {
        int v0 = this.g.isEmpty() ? -1 : this.g.bottom - this.g.top;
        return v0;
    }

    public final int getIntrinsicWidth() {
        int v0 = this.g.isEmpty() ? -1 : this.g.right - this.g.left;
        return v0;
    }

    public final int getOpacity() {
        return this.c.getAlpha();
    }

    public final boolean isStateful() {
        return this.f.isStateful();
    }

    protected final void onBoundsChange(Rect arg2) {
        this.g.set(arg2);
    }

    protected final boolean onStateChange(int[] arg2) {
        return this.a(arg2);
    }

    public final void setAlpha(int arg2) {
        if(this.c.getAlpha() != arg2) {
            this.c.setAlpha(arg2);
        }
    }

    public final void setColorFilter(ColorFilter arg2) {
        if(this.c.getColorFilter() != arg2) {
            this.c.setColorFilter(arg2);
        }
    }
}

